package com.project.service;
import com.project.dao.UserDao;
import com.project.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public boolean hasMatchUser(String userName, String password){
        int matchCount = userDao.getMatchCount(userName, password);
        System.out.println("数据库匹配人数："+matchCount);
        return matchCount > 0;
    }

    public User findUserByUserName(String userName){
//        System.out.println("数据库匹配到："+userDao.findUserByUserName(userName));
        return userDao.findUserByUserName(userName);
    }

//    @Transactional
//    public void loginSuccess(User user){
//        LoginLog loginLog = new LoginLog();
//        loginLog.setUserId(user.getUserId());
//        loginLog.setIp(user.getLastIp());
//        loginLog.setLoginDate(user.getLastVisit());
//        System.out.println(user.toString());
//        userDao.updateLoginInfo(user);
//        loginLogDao.insertLoginLog(loginLog);
//    }
}

